package net.helix.engine.library.items;

import java.io.File;

import net.helix.core.geometry.Geometry_Image;
import net.helix.element.Element;
import net.helix.element.Element_Image;
import net.helix.engine.Engine;
import net.helix.engine.library.Library;
import net.helix.engine.properties.Properties;
import net.helix.engine.properties.Properties_Image;

import org.lwjgl.opengl.GL11;
import org.newdawn.slick.opengl.Texture;


public class LibraryItem_Image extends LibraryItem {
	// TODO: make static float buffer to speed up rendering
	
	// TODO: use the Image object instead of the slick Texture object to store the image...
	
	private Geometry_Image image;
	
	public LibraryItem_Image(Library library, String name, File file){
		super(library, name);
		this.type = LibraryItemType.IMAGE;
		
		image = new Geometry_Image(file.getPath());
	}
	public LibraryItem_Image(Library library, String name, Geometry_Image image){
		super(library, name);
		this.type = LibraryItemType.IMAGE;
		
		this.image = image;
	}
	
	@Override
	public void dispose(){
		
	}

	@Override
	public void renderLibrary(Engine engine, int width, int height) {
		//GL11.glLoadIdentity();
		//GL11.glScalef(1/image.getWidth(), 1/image.getHeight(), 1);
		
		GL11.glMatrixMode(GL11.GL_PROJECTION);
		GL11.glOrtho(0, image.getWidth(), 0, image.getHeight(), 1, -1);
		GL11.glMatrixMode(GL11.GL_MODELVIEW);
		GL11.glLoadIdentity();
		
		image.render();
	}
	@Override
	public void render(Properties properties) {
		image.render();
	}
	public int getTexId(){
		return image.getTexId();
	}
	public Texture getTex(){
		return image.getTex();
	}
	@Override
	public Properties makeDefaultProperties() {
		return new Properties_Image();
	}
	@Override
	public Element createElement() {
		return new Element_Image(this);
	}
}
